package search;

import test.User;

@Mapper // Spring Boot 中标识为 MyBatis 映射器
public interface UserMapper {
    //查询接口
    List<User> selectByCondition(UserQuery query);
    // 插入并返回自增主键
    @Insert("INSERT INTO user(username, password, email, create_time) " +
            "VALUES(#{username}, #{password}, #{email}, #{createTime})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(User user);
    
    // 根据ID查询
    @Select("SELECT * FROM user WHERE id = #{id}")
    User selectById(Long id);
    
    // 更新
    @Update("UPDATE user SET username=#{username}, email=#{email} WHERE id=#{id}")
    int update(User user);
    
    // 删除
    @Delete("DELETE FROM user WHERE id = #{id}")
    int deleteById(Long id);
    
    // 查询所有
    @Select("SELECT * FROM user")
    List<User> selectAll();
}